<?php
class UserIdentity extends CUserIdentity
{
	private $_id;
	private $_role;
	
	public function authenticate()
	{
		$user = Staffs::model()->findByAttributes(array('username'=>$this->username));
		
		if ($user===null)
				$this->errorCode=self::ERROR_USERNAME_INVALID;
        else {
			if (!CPasswordHelper::verifyPassword($this->password, $user->password) || $user->status == 'I')
    			$this->errorCode=self::ERROR_USERNAME_INVALID;
    		else {
                $user->updateByPk($user->id, array("lastlogin"=>new CDbExpression('NOW()')));
                $this->_id=$user->id;
				//Yii::app()->user->setState('role', $user->role);
			    $this->errorCode=self::ERROR_NONE;
    		}
		}
		return !$this->errorCode;
	}
	
	public function getId()
	{
		return $this->_id;
	}
}